/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dp.controller;

import com.dp.model.Articles;
import com.dp.services.IItemServices;
import com.dp.services.ItemServices;
import com.dp.utils.BaseException;
import com.dp.dto.ArticleAddDTO;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author hisik
 */
public class ArticleAddController {
 
    private static final IItemServices itemServices = new ItemServices();
        
    public static void saveNewArticle(ArticleAddDTO dto) throws BaseException {
        
        Long objid              = dto.getObjid();
        String issueArea        = dto.getIssueArea();
        int issueDate           = dto.getIssueDate();
        int authorCount         = dto.getAuthorCount();
        String articleName      = dto.getArticleName();
        int pageCount           = dto.getPageCount();
        String publisherName    = dto.getPublisherName();
        String journalName    = dto.getJournalName();
        String volume = dto.getVolume();
        String issue = dto.getIssue();
        
        Calendar c = new GregorianCalendar();
        c.set(Calendar.YEAR, issueDate);
        Date date = c.getTime();
        
        itemServices.saveOrUpdateArticles(objid, authorCount, articleName, 
                issue, issueArea, date, journalName, pageCount, publisherName, 
                volume);
    }
    
    public static Articles getArticlesByObjid(ArticleAddDTO dto) throws BaseException {
        Long objid = dto.getObjid();
        
        return itemServices.getArticlesByObjid(objid);
    }
}
